from pms.common.views import PostFormula
from project.utils.role import project_role_view, update_project_role
from project.models import ProjectRole
from project.utils.permission import assert_project_permissions


class API(PostFormula):
    def handle(self, req):
        rid = req['rid']
        mod = req['mod']
        project_role = ProjectRole.objects.get(id=rid)
        assert_project_permissions(project_role.pid_id, self.user.id, [4])
        return self.success_respond(project_role_view(
            project_role=update_project_role(
                project_role=project_role,
                view=mod
            )
        ))
